if(!localStorage.getItem('token')){
    localStorage.removeItem('token')
    location.href ='/login.html'
}

//1. 获取用户信息 渲染到个人信息
// const baseUrl='http://api-breakingnews-web.itheima.net'
function getUser(){
    // axios.get(`${baseUrl}/my/userinfo`,{
    //     headers:{
    //         Authorization:localStorage.getItem('token')
    //     }
    // }).then(res =>{
    //     if(res.data.status === 0){
    //        let {id,username,nickname,email,user_pic}=res.data.data
    //        username = nickname || username
    //        if(!user_pic){
    //         $('.avatar').css('display','inline-block').html(username[0].toUpperCase())
    //        }else{
    //         $('.avatar').css('display','none')
    //         $('.layui-nav-img').css('display','inline-block').attr('src',user_pic)
    //        }
    //        $('.username').html(username)
    //     }else{
    //         //
    //         localStorage.removeItem('token')
    //         location.href ='/login.html'
    //     }
    // })
    getUserInfoMethod(res=>{
        if(res.data.status === 0){
                   let {id,username,nickname,email,user_pic}=res.data.data
                   username = nickname || username
                   if(!user_pic){
                    $('.avatar').css('display','inline-block').html(username[0].toUpperCase())
                   }else{
                    $('.avatar').css('display','none')
                    $('.layui-nav-img').css('display','inline-block').attr('src',user_pic)
                   }
                   $('.username').html(username)
                }else{
                    //
                    localStorage.removeItem('token')
                    location.href ='/login.html'
                }
    })
}
getUser()
//2.退出模块功能
$('#logout').on('click',()=>{
    layer.confirm('确定要退出吗?', {icon: 3, title:'温馨提示'}, function(index){
        //do something
        localStorage.removeItem('token')
        location.href ='/login.html'
        layer.close(index);
      });
})